package com.oceansoft.mobile.econsole.modules.weixin.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.oceansoft.mobile.econsole.common.constant.ConfigInfo;
import com.oceansoft.mobile.econsole.common.util.HttpClientUtil;
import com.oceansoft.mobile.econsole.modules.base.entity.Result;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * ClassName: ApiCodeController
 * Desc: 获取验证码
 * Date： 2017/3/31
 * Created：shaom
 */
@RestController
@RequestMapping("api/code")
public class ApiCodeController {

    @Resource
    ConfigInfo configInfo;

    @RequestMapping(value = "get/{id}", method = RequestMethod.GET)
    public Result getCode(@PathVariable("id") String id) {
        String url = configInfo.getServiceInterfaceAddress() + "/base/captcha/" + id;
        String str = HttpClientUtil.doPostString(url, null);
        System.out.println(str);
        Objects.requireNonNull(str, "返回数据为空");

        JSONObject jsonObject = JSON.parseObject(str);
        return new Result(jsonObject.getBooleanValue("succ"), jsonObject.getString("data"), jsonObject.getString("msg"));
    }


}
